%set(gcf, 'Renderer', 'painters');
%set(gca,'nextplot','replacechildren');
%set(gca,'replace');
%set(gcf,'Renderer','zbuffer');
close all;
clear all;

recafr = VideoWriter('recafr3.avi','Uncompressed AVI');
%reccfr = VideoWriter('reccfr3.avi','Uncompressed AVI');
%cdc42fr = VideoWriter('cdc42fr3.avi','Uncompressed AVI');
recafr.FrameRate = 1;
%reccfr.FrameRate = 3;
%cdc42fr.FrameRate = 3;
open(recafr);
%open(reccfr);
%open(cdc42fr);

recat=importdata('data_reca_time_course',' ');
recct=importdata('data_receptor_time_course',' ');
N=size(recat,2);
fig2=figure(2);
hold off;
if mod(size(recat,1),size(recat,2))~=0
    display('Some frames were not fully written! The further progression of the script will be erroneous\n');
else
    Nf=size(recat,1)/size(recat,2);
    fig2=figure(2);
    %clf reset;
    for i=0:(Nf-1)
        r=recat(1+i*N:N+i*N,:)+recct(1+i*N:N+i*N,:);
        image(r);
        title('Receptor bound to pheromone');
        fr=getframe(fig2);
        writeVideo(recafr,fr);
    end
end

%set(gcf, 'Renderer', 'painters');
close(recafr);
%reccfr.close;
%cdc42fr.close;